﻿//创建时间: 2010-12-19
//创建作者: 李 城
//功能说明: 插件辅助操作方法
//最后修改: 2011-1-24
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Web.UI.WebControls;

using TRPOP.Common;
using TRPOP.Config;
using TRPOP.CMS.Model;


namespace TRPOP.CMS.Plugin
{
    /// <summary>
    /// 插件辅助类
    /// </summary>
    public class PluginAssistForTemplate : System.IDisposable
    {
        

        #region 模板设置的基本委托、事件
        public delegate void delNodeTemplateHander(Literal ltTemplate, int intNodeid);
        public event delNodeTemplateHander NodeTemplateShowEvent;

        public delegate void delSaveNodeTemplate(int intNodeid);
        public event delSaveNodeTemplate NodeTemplateSaveEvent;
        #endregion

        #region 模板设置 的基本调用函数
        /// <summary>
        /// 初始化模板设置
        /// </summary>
        /// <param name="ltTemplate"></param>
        /// <param name="intNodeid"></param>
        public void InitPluginTemplate(Literal ltTemplate, int intNodeid)
        {
            if (NodeTemplateShowEvent != null)
            {
                NodeTemplateShowEvent(ltTemplate, intNodeid);
            }
        }
        /// <summary>
        /// 获取模板设置
        /// </summary>
        /// <param name="intNodeid"></param>
        public  void SavePluginTemplate(int intNodeid)
        {
            if (NodeTemplateSaveEvent != null)
            {
                NodeTemplateSaveEvent(intNodeid);
            }
        }
        #endregion

        /// <summary>
        /// 添加模板中的变量
        /// </summary>
        /// <param name="oDictionary"></param>
        /// <param name="oPageInfo"></param>
        public void InitTemplateEngeen(Dictionary<string, string> oDictionary, string ContentIdOut)
        {
            #region 评论插件
            if (SYSConfig.RecommentConfigerInfo.Enable)
            {
                if (oDictionary.ContainsKey("RecommentGetCountUrl") == false)
                    oDictionary.Add("RecommentGetCountUrl", SYSConfig.RecommentConfigerInfo.URL_GetCount);
                if (oDictionary.ContainsKey("RecommentSubmitUrl") == false)
                    oDictionary.Add("RecommentSubmitUrl", SYSConfig.RecommentConfigerInfo.URL_Submit);
                if (oDictionary.ContainsKey("RecommentListUrl") == false)
                    oDictionary.Add("RecommentListUrl", SYSConfig.RecommentConfigerInfo.URL_List);
                if (oDictionary.ContainsKey("RecommentCheckCodeUrl") == false)
                    oDictionary.Add("RecommentCheckCodeUrl", SYSConfig.RecommentConfigerInfo.URL_CheckCode);
                oDictionary["RecommentGetCountUrl"] = SYSConfig.RecommentConfigerInfo.URL_GetCount.ToLower().Replace("{indexid}", ContentIdOut);
                oDictionary["RecommentListUrl"] = SYSConfig.RecommentConfigerInfo.URL_List.ToLower().Replace("{indexid}", ContentIdOut)
                                                                                       .Replace("{page}", "1");

            }
            #endregion
        }

        #region 释放资源 
        private bool mDisposed = false;
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
            //throw new NotImplementedException();
        }
        protected virtual void Dispose(bool disposing)
        {
            if (mDisposed)
                return;
            if (disposing)
            {
                //do dispose
            }
            mDisposed = true;
        }
        ~PluginAssistForTemplate()
        {
            Dispose(false);
        }
        #endregion
    }
}
